package com.atguigu4.search_sort.exer1;

/**
 * ClassName: arrary_test1
 * Description:
 *现有数组 int[] arr = new int[]{1,2,3,4,5};
 * 现将数组长度扩容1倍，并将10,20,30三个数据添加到arr数组中，如何操作？
 * @Author liu
 * @Create 2024/8/12 19:35
 * @Version 1.0
 */

public class arrary_test1 {
    public static void main(String[] args) {
        //新建个数组，代替
        int[] arr = new int[]{1,2,3,4,5};

        //扩容数组
        //int[] newarr = new int[arr.length * 2];
        int[] newarr = new int[arr.length << 1];

        for (int i = 0; i <arr.length ; i++) {
            newarr[i] = arr[i];
        }

        newarr[arr.length] = 10;
        newarr[arr.length +1] = 20;
        newarr[arr.length +2] = 30;

        //代换
        arr = newarr;

        for (int i = 0; i <arr.length ; i++) {
            System.out.print(arr[i]+" ");

        }
    }
}
